#include <iostream>
#include <vector>
#include "overlap.hpp"
#include "vecs_io.cpp"

using namespace std;
using namespace KMeansMultipleOverlapBoundary;

/*
 * 输入有single_partition.txt, distance_idx.txt
 * 参数传递有: train_para_dir n_cluster n_item
 * 输出为partition.txt, overlap为2
 */

int main(int argc, char **argv) {
    if (argc != 3) {
        std::cout << argv[0] << " train_para_dir overlap_proportion" << std::endl;
        exit(-1);
    }
    printf("path %s\noverlap_proportion %s\n", argv[1], argv[2]);

    char *path = argv[1];
    float overlap_proportion = atof(argv[2]);

    vector<int> distance_idx;
    vector<int> single_partition;
    vector<int> cluster_len;
    int n_cluster, n_item;
    read_parameter(distance_idx, single_partition, cluster_len, n_cluster, n_item, path);

    char centroid_l_path[256];
    sprintf(centroid_l_path, "%s/distance2nearest_centroid_idx.ivecs", path);
    int tmp_n_cluster, tmp_n_item;
    int *distance_to_centroid_idx = load_vecs<int>(centroid_l_path, tmp_n_item, tmp_n_cluster);

    //add the overlap to the partition.txt
    vector<pair<int, int>> overlap_partition = get_overlap_partition(distance_idx, single_partition, cluster_len,
                                                                     distance_to_centroid_idx, overlap_proportion);
    printf("get overlap partition\n");
    save_overlap_partition(overlap_partition, path);
    printf("save overlap partition\n");
    return 0;
}